﻿using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PlayListSet.Entity
{
    public class UpdateSourceModel : System.ComponentModel.INotifyPropertyChanged
    {
        public UpdateSourceModel() {
            UserCommand = new UserCommand();
        }
        public long ID { get; set; }
        public bool IsData { get; set; }
        public string Name { get; set; }
        public string Channel { get; set; }
        public string SourceUrl { get; set; }
        public ChannelInfo ChannelInfo { get; set; }

        private double size = 0;
        public double Size
        {
            get => size;
            set
            {
                size = value;
                PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Size"));
                PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("SizeStr"));

            }
        }
        public string SizeStr
        {
            get
            {
                double s = size / 1024 / 1024;
                return s.ToString("0.00") +"mb";

            }

        }
        private double currentSize=0;
        public double CurrentSize
        {
            get => currentSize;
            set
            {
                currentSize = value;
                PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("CurrentSize"));
                PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("UpdateSizeStr"));

            }
        }
        public string UpdateSizeStr
        {
            get
            {
                if (size == 0) return "0.00%";
               var u =( currentSize / size)*100;
                return u.ToString("0.00") + "%";
            }
        
        }
        private string state = "等待下载";
        public string State
        {
            get => state;
            set
            {
                state = value;
                PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("State"));
            }
        }
        private string msg = "等待下载";
        public string Msg
        {
            get => msg;
            set
            {
                msg = value;
                PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Msg"));
            }
        }
        public event PropertyChangedEventHandler PropertyChanged;
        [JsonIgnore]
        public UserCommand UserCommand { set; get; }
    }
}
